new Vue({
    el: '#app',
    data() {
        return {
            html: '',
            options: [{
                value: 0,
                label: '用户服务协议'
            }, {
                value: 1,
                label: '隐私协议'
            }, {
                value: 2,
                label: '用户授权协议'
            }],
            form: {
                Company_Honors_SerialNumber: "",
                Company_Honors_Name: '',
                Picture_URL: '',
            }
        }
    },
    methods: {
        handlePictureCardPreview(file) {
            this.dialogVisible = true
            this.dialogImageUrl = file
        },
        handleRemove(type, index) {
            this.form.Picture_URL = ''
        },
        uploadFront(file) {
            let _this = this
            let num = 1
            if (file.size > 150000 && file.size < 500000) {
                num = 0.4
            } else if (file.size > 500000) {
                num = 0.2
            }
            new Compressor(file, {
                quality: num,
                // if(file.size) {
                // }
                success(file) {
                    console.log(file.size)
                    const formData = new FormData();
                    formData.append('file', file, file.name);
                    let oFileReader = new FileReader();
                    oFileReader.readAsDataURL(file);
                    oFileReader.onload = function (e) {
                        $.ajax({
                            type: 'POST',
                            url: DomainName + '/BusinessPIC',
                            data: {
                                Data: e.target.result,
                                DataLength: file.size,
                                FileName: file.name,
                                logo:true
                            },
                            complete: function (XMLHttpRequest) {
                                _this.loading = false
                                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                                    window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                                }
                            },
                            success: function (Result) {
                                _this.form.pic = e.target.result
                                if (Result.Status == "success") {
                                    _this.form.Picture_URL = Result.Picture_Url
                                    _this.$message.success('上传成功')
                                    console.log(Result.Picture_Url);
                                } else {
                                    _this.$message.error('上传失败')
                                }
                            },
                            error: function () {
                                _this.$message.error("操作失败，请稍后再试")
                            },
                            dataType: "json"
                        });
                    }
                },
                error(err) {
                    console.log(err.message);
                },
            });
        },
        back() {
            window.history.go(-1)
        },
        subMessage() {
            const _this = this
            console.log(this.form)
            $.ajax({
                url: DomainName + '/GoodsFileAdd',
                type: 'POST',
                data: {
                    Data: JSON.stringify({
                        company_honors: [_this.form]
                    }),
                    token: $.cookie("token")
                },
                success: function (res) {
                    console.log('提交结果', res)
                    if (res.Status == 'success') {
                        _this.$message.success("发布成功!")
                        window.history.go(-1)
                    }
                },
                error: function () {
                    _this.$message.error("操作失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                    _this.loading = false
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                }
            })
        }
    },
})